import pygame

# Define some colors
black	= (0, 0, 0)
white	= (255, 255, 255)
green	= (0, 255, 0)
red	= (255, 0, 0)
blue	= (0, 0, 255)

# Initialize the game engine
pygame.init()

# Set the height and width of the screen
width	= 700
height	= 500
size 	= [width, height]
screen 	= pygame.display.set_mode(size)

pygame.display.set_caption("Title")

# Loop until the user clicks the close button
done = False
clock = pygame.time.Clock()

fps = 60

# Starting position of the rectangle
rect_x = 50
rect_y = 50

# Speed and direction of rectangle
rect_change_x = 5
rect_change_y = 5

# ----- Main Program Loop -----
while not done:
	# For everything the user does
	for event in pygame.event.get():
		if event.type == pygame.QUIT:
			done = True

	# Set the screen background
	screen.fill(black)

	# ----- Begin Drawing Something -----

	# Draw the rectangle
	pygame.draw.rect(screen, white, [rect_x, rect_y, 50, 50])

	# Move the rectangle starting point
	rect_x += rect_change_x
	rect_y += rect_change_y

	# Bounce the ball if needed
	if rect_x > (width - 50) or rect_x < 0:
		rect_change_x *= -1;
	if rect_y > (height - 50) or rect_y < 0:
		rect_change_y *= -1;

	# ----- End Drawing Something -----

	# Limit to fps frames per second
	clock.tick(fps)

	# Update the screen with what's been drawn
	pygame.display.flip()

# Exit.
pygame.quit()
